package cn.wzy.controller;



import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Car;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.CarSearchService;
import cn.wzy.service.CarService;
import cn.wzy.vo.CarSearchQuery;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.annotation.TableName;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Car)表控制层
 *
 * @author makejava
 * @since 2023-01-24 10:49:06
 */
@RestController
@RequestMapping("car")
@ApiOperation(value = "车辆管理")
@AnPermission(name = "车辆管理")
public class CarController{
    /**
     * 服务对象
     */
    @Resource
    private CarService carService;

    @Resource
    private CarSearchService carSearchService;
    
    /*
    * 查询分页
    * */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询",tags = "分页")
    @AnPermission(name = "车辆分页")
    public ResponseResult getCarPage(@RequestBody GoPageVo goPageVo){
        return carService.getCarPage(goPageVo);
    }

    /*
    * 查询
    * */
    @GetMapping("/{id}")
    @AnPermission(name = "车辆id查询")
    @ApiOperation(value = "车辆id查询")
    public ResponseResult getCar(@PathVariable("id") Long id){
        return carService.getCar(id);
    }

    /*
    * 新增和修改
    * */
    @PutMapping
    @AnPermission(name = "车辆修改或者添加")
    @ApiOperation(value = "车辆新增或者修改")
    public ResponseResult saveCar(@RequestBody Car car){
        return carService.saveCar(car);
    }

    /*
    * 删除
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "id删除车辆")
    @ApiOperation(value = "删除车辆")
    public ResponseResult deleteCar(@PathVariable("id") Long id){
        return carService.deleteCar(id);
    }


    /*
    * 批量删除
    * */
    @PatchMapping
    @AnPermission(name = "批量删除车辆")
    @ApiOperation(value = "批量删除车辆")
    public ResponseResult deleteCarList(@RequestBody List<Long> ids){
        return carService.deleteCarList(ids);
    }


    /*
    * 上架
    * */
    @PostMapping("/onsale")
    public ResponseResult onsale(@RequestBody List<Long> ids){
        return carService.onsale(ids);
    }

    /*
    * 下架
    * */
    @PostMapping("/offsale")
    public ResponseResult offsale(@RequestBody List<Long> ids){
        return carService.offsale(ids);
    }

    /*
    * 查询es中list
    * */
    @PostMapping("/list")
    public ResponseResult search(@RequestBody CarSearchQuery searchQuery){
        return carSearchService.search(searchQuery);
    }

}

